package com.tj.view.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutCompat;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tj.view.R;
import com.tj.view.view.FlowLayout;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/1/16 0016.
 */

public class FlowLayoutActivity extends AppCompatActivity {

    private String[] mVals = new String[]{
             "hello","welcome","button imageview","textview"
            ,"hello","welcome nanjin","button","textview"
            ,"hello","welcome","button","textview come"};


    @Bind(R.id.view_flowlayout)
    FlowLayout mFlowLayout;
    @Bind(R.id.view_flowlayout_two)
    FlowLayout mFlowLayout_two;
    @Bind(R.id.view_flowlayout_three)
    FlowLayout mFlowLayout_three;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flowlayout);
        ButterKnife.bind(this);

        initData();
        initDataTwo();
    }

    private void initData() {

        for(int i=0; i<mVals.length; i++){

            Button btn = new Button(this);

            //viewgroup的
            ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(
                    LinearLayoutCompat.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);

            btn.setText(mVals[i]);
            //动态添加btn
            mFlowLayout.addView(btn,lp);
        }
    }

    private void initDataTwo(){

        TextView textView = null;
        for(int i=0; i<mVals.length; i++){

            textView = (TextView)LayoutInflater.from(this).inflate(R.layout.tv, mFlowLayout_two, false);
            textView.setText(mVals[i]);
            ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) textView.getLayoutParams();
            lp.setMargins(10,10,10,10);
            textView.setLayoutParams(lp);

            //动态添加btn
            mFlowLayout_two.addView(textView);
        }
    }

}
